package com.jliang.apps.controller;

import com.jliang.apps.fanout.FanoutSender;
import com.jliang.apps.sender.RabbitSender;
import com.jliang.apps.topic.TopicSender;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author jijinliang
 * @title: SenderController
 * @projectName spring-boot-rabbitmq-cluster
 * @description: TODO
 * @date 2019/2/27 9:56
 */
@RestController
@RequestMapping("/mq")
public class SenderController {
	/**
	 * 定义rabbitSender句柄.
	 */
	@Autowired
	private RabbitSender rabbitSender;

	@Autowired
	private TopicSender topicSender;
	
	@Autowired
	private FanoutSender fanoutSender;
	
	@Autowired
	@Qualifier("restTemplateA")
	private RestTemplate restTemplateA;
	
	@Autowired
	@Qualifier("restTemplateB")
	private RestTemplate restTemplateB;

	/**
	 * 发送消息
	 *
	 * @return
	 */
	@GetMapping("/send")
	public String sendMsg() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		Map<String, Object> properties = new HashMap<>();
		properties.put("number", "12345");
		properties.put("send_time", simpleDateFormat.format(new Date()));
		rabbitSender.send("订单号:SW2019123456784", properties);
		return "SUCCESS";
	}

	/**
	 * 发送消息
	 *
	 * @return
	 */
	@GetMapping("/fanoutSenderMsg")
	public String fanoutSenderMsg() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		Map<String, Object> properties = new HashMap<>();
		properties.put("number", "12345");
		properties.put("send_time", simpleDateFormat.format(new Date()));
		fanoutSender.send("订单号:SW2019123456784" + simpleDateFormat.format(new Date()));
		return "SUCCESS";
	}
	
	/**
	 * 发送消息
	 *
	 * @return
	 */
	@GetMapping("/sendTopicMsg")
	public String sendTopicMsg() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		Map<String, Object> properties = new HashMap<>();
		properties.put("number", "12345");
		properties.put("send_time", simpleDateFormat.format(new Date()));
		topicSender.send("订单号:SW2019123456784" + simpleDateFormat.format(new Date()));
		return "SUCCESS";
	}
}
